package com.ruoyi.web.controller.business;

import java.util.List;

import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.service.IBusinessinfoService;
import com.ruoyi.system.service.IComplaintService;
import com.ruoyi.system.service.IComplainttypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Complaint;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 客户投诉 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-07-16
 */
@Controller
@RequestMapping("/system/complaint")
public class ComplaintController extends BaseController
{
    private String prefix = "system/complaint";
	
	@Autowired
	private IComplaintService complaintService;
	@Autowired
	private IComplainttypeService complainttypeService;
	@Autowired
	private IBusinessinfoService businessinfoService;

	
	@RequiresPermissions("system:complaint:view")
	@GetMapping()
	public String complaint()
	{
	    return prefix + "/complaint";
	}
	
	/**
	 * 查询客户投诉列表
	 */
	@RequiresPermissions("system:complaint:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Complaint complaint)
	{
		startPage();
        List<Complaint> list = complaintService.selectComplaintList(complaint);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出客户投诉列表
	 */
	@RequiresPermissions("system:complaint:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Complaint complaint)
    {
    	List<Complaint> list = complaintService.selectComplaintList(complaint);
        ExcelUtil<Complaint> util = new ExcelUtil<Complaint>(Complaint.class);
        return util.exportExcel(list, "complaint");
    }
	
	/**
	 * 新增客户投诉
	 */
	@GetMapping("/add")
	public String add(ModelMap mmap)
	{
		mmap.put("complaintTypes",complainttypeService.selectComplainttypeList(null));
		mmap.put("businessInfos",businessinfoService.selectBusinessinfoList2(null));
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存客户投诉
	 */
	@RequiresPermissions("system:complaint:add")
	@Log(title = "客户投诉", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Complaint complaint)
	{
		SysUser user = getSysUser();
		complaint.setHuiyuanId(user.getUserId());
		complaint.setChuliJindu("0");
		return toAjax(complaintService.insertComplaint(complaint));
	}

	/**
	 * 修改客户投诉
	 */
	@GetMapping("/edit/{complaintId}")
	public String edit(@PathVariable("complaintId") Integer complaintId, ModelMap mmap)
	{
		Complaint complaint = complaintService.selectComplaintById(complaintId);
		mmap.put("complaintTypes",complainttypeService.selectComplaintIdList(complaintId));
		mmap.put("businessInfos",businessinfoService.selectBusinessinfoByComlaintId(complaintId));
		mmap.put("complaint", complaint);
	    return prefix + "/edit";
	}
	@GetMapping("/chuli/{complaintId}")
	public String chuli(@PathVariable("complaintId") Integer complaintId, ModelMap mmap)
	{
		Complaint complaint = complaintService.selectComplaintById(complaintId);
		mmap.put("complaint", complaint);
		mmap.put("complaints",complaintService.selectComplaintList(null));
		return "system/complaintchuli/complaintchuli";
	}
	/**
	 * 修改保存客户投诉
	 */
	@RequiresPermissions("system:complaint:edit")
	@Log(title = "客户投诉", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Complaint complaint)
	{		
		return toAjax(complaintService.updateComplaint(complaint));
	}
	
	/**
	 * 删除客户投诉
	 */
	@RequiresPermissions("system:complaint:remove")
	@Log(title = "客户投诉", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(complaintService.deleteComplaintByIds(ids));
	}
	
}
